// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    from: "所有",
    to: "所有",

    taskArrayShown:[],
    taskArray: [],

  },



  taskTap(e) {
    if (app.globalData.isGetUserInfo == false) {
      wx.showToast({
        icon: "none",
        title: '请先登录'
      })
      return
    }
    wx.navigateTo({
      url: '../task_detail/task_detail?data=' + e.currentTarget.dataset.task._id,
    })
  },

  onLoad() {
  },

  onShow() {
    wx.cloud.callFunction({
      name: "getTaskList",
      data: {
        action: "getHomeTask",
      },
      success: (res) => {
        console.log(res)
        this.setData({
          taskArray: res.result
        })
        let taskArrayShown=this.data.taskArray.filter(item=>(this.data.from=="所有"||item.from==this.data.from)&&(this.data.to=="所有"||item.to==this.data.to))
        this.setData({
          taskArrayShown:taskArrayShown
        })
        console.log(this.data.from,this.data.to)
        console.log(this.data.taskArrayShown)
      },
      fail: (res) => {
        console.log(res)
      }
    })
  },

})